<?php

namespace app\api\service;

use app\api\controller\Validate;
use app\api\model\AgentCompanyModel;
use app\api\model\AgentModel;
use app\api\model\CategoryModel;
use app\api\model\CompanyModel;
use app\api\model\ProductChannelModel;
use app\api\model\ProductCommissionModel;
use app\api\model\ProductConfigModel;
use app\api\model\ProductInfoModel;
use app\api\model\ProductModel;
use app\api\model\ProductPlanCostModel;
use app\api\model\ProductPlanNoRateModel;
use app\api\model\ProductPlatModel;
use app\api\model\ProductRuleModel;
use app\api\model\WorkCategoryModel;
use app\api\model\WorkTypeModel;
use app\common\model\Area;
use think\Db;
use think\Request;

class ClientProductService extends Api
{
    protected static $instance;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
    }

    public static function getInstance()
    {
        if (is_null(self::$instance))
        {
            self::$instance = new static();
        }
        return self::$instance;
    }

    /**
     * 获取可见产品列表
     */
    public function getProductList($params)
    {
        $params['admin_id'] = $this->uid;
        $Validate = new \think\Validate([
            'admin_id' => 'require',
        ], [
            'admin_id' => '缺少账号标识'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }

        //查询全部产品
        $allPro = ProductModel::getInstance()->selectProduct([
            'product_status' => ['eq', 2]
        ]);
        $allProIds = array_column($allPro, 'id');
        //查询当前账号创建产品
        $adminPro = ProductModel::getInstance()->selectProduct([
            'product_status' => ['eq', 2],
            'c_id' => ['eq', $params['admin_id']]
        ]);
        $adminProIds = array_column($adminPro, 'id');
        //查询当前账号配置可见产品
        $channelPro = ProductChannelModel::getInstance()->select([
            'admin_id' => ['eq', $params['admin_id']],
            'status' => ['eq', 1]
        ]);
        $channelProIds = array_column($channelPro, 'product_id');
        $proIds = $params['admin_id'] > 1 ? array_merge($adminProIds, $channelProIds) : array_merge($allProIds, $adminProIds, $channelProIds);

        //获取产品标签
        $proLabelWhere = [
            'field' => ['eq', 'product_label'],
            'pro_id' => ['in', $proIds],
        ];
//        $proLabel = ProductInfoModel::getInstance()->column($proLabelWhere, 'content');
        if (isset($params['productLabel']))
        {
            $ids = '';
            foreach ($params['productLabel'] as $item)
            {
                $proLabelWhere['content'] = ['like', '%'.$item.'%'];
                $labelIds = array_keys(ProductInfoModel::getInstance()->column($proLabelWhere, 'content'));
                $ids .= empty($labelIds) ? $ids : (empty($ids) ? implode(',', $labelIds) : ','.implode(',', $labelIds));
            }
            $proIds = explode(',', $ids);
        }

        //获取拒保行业
        $nonInsured = ProductInfoModel::getInstance()->column([
            'field' => ['eq', 'non_insured'],
            'pro_id' => ['in', $proIds]
        ], 'content');
        //获取产品保障周期
        $insureType = ProductInfoModel::getInstance()->column([
            'field' => ['eq', 'insure_type'],
            'pro_id' => ['in', $proIds]
        ], 'content');
        //获取产品标签设定值
        $labelConfig = ProductConfigModel::getInstance()->value([
            'name' => ['eq', 'product_label']
        ]);
        $companyList  = CompanyModel::getInstance()->column([], 'name');
        $cateList = CategoryModel::getInstance()->column([], 'title');

        $where = [
            'id' => ['in', $proIds],
            'product_status' => ['eq', 2]
        ];

        if (isset($params['product_cate']))
        {
            $where['product_cate'] = ['in', $params['product_cate']];
        }
        if (isset($params['company_id']))
        {
            $where['company'] = ['in', $params['company_id']];
        }

        $proList = ProductModel::getInstance()->selectProduct($where, '*', 0, 1000000, 'sort');

        $productCommission = ProductChannelModel::getInstance()->column([
            'admin_id' => ['eq', $params['admin_id']],
            'product_id' => ['in', array_column($proList, 'id')],
            'status' => ['eq', 1]
        ], 'promotion_commission, step_commission, commission_type', 'product_id');

        $result = [];
        foreach ($proList as $k => $v)
        {
            //产品名称  所属保司  险种类型  保障周期  拒保行业  投保按钮
            $result[$k]['product_id'] = $v['id'];
            $result[$k]['product_name'] = $v['product_name'];
            $result[$k]['product_code'] = $v['product_code'];
            $result[$k]['product_cate'] = $cateList[$v['product_cate']];
            $result[$k]['insure_type'] = '年保';
            $result[$k]['product_label'] = '';
            $result[$k]['company_name'] = $companyList[$v['company']];
            foreach ($insureType as $kk => $vv)
            {
                if ($kk == $v['id'])
                {
                    $vv = json_decode($vv, true);
                    $result[$k]['insure_type'] = in_array(1, $vv) ? (in_array(2, $vv) ? '月保/年保' : '年保') : '月保';
                }
            }
            foreach ($nonInsured as $kk => $vv)
            {
                if ($kk == $v['id'])
                {
                    $result[$k]['product_label'] = $vv;
                }
            }
            $result[$k]['proCommission'] = 0;

            if (isset($productCommission[$v['id']]))
            {
                $proCommission = $productCommission[$v['id']];
                switch ($proCommission['commission_type'])
                {
                    case 1:
                        $result[$k]['proCommission'] = $proCommission['promotion_commission'];
                        break;
                    case 2:
                        $stepCommission = json_decode($proCommission['step_commission'], true);
                        $result[$k]['proCommission'] = min(array_column($stepCommission, 'ratio'));
                        break;
                }
            }
        }
        return $result;
    }

    /**
     * 获取产品详情
     */
    public function getProductDetail($params)
    {
        $Validate = new \think\Validate([
            'product_id' => 'require',
        ], [
            'product_id' => '产品标识无效'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }
        $product = ProductModel::getInstance()->find($params['product_id']);
        $productInfo = ProductInfoModel::getInstance()->column([
            'pro_id' => ['eq', $params['product_id']]
        ], 'content', 'field');
        foreach ($productInfo as $k => &$v)
        {
            $v = strpos($v, '{') !== false ? json_decode($v, true) : $v;
        }
        $proInfo = array_merge($product, $productInfo);
        $insure_clause = $proInfo['insure_clause'];

        $proRule = ProductRuleModel::getInstance()->find($params['product_id']);
        $proInsureRule = json_decode($proRule['insure_rule'], true);
        $baseRule = json_decode($proRule['base_rule'], true);
        $timeRule = json_decode($proRule['time_rule'], true);

        $proInfo['insureTime'] = isset($proInsureRule['month']) ? (count($proInsureRule['month']) > 1 ? min($proInsureRule['month']) . '-' . max($proInsureRule['month']) . '个月' : max($proInsureRule['month']) . '个月') : '';
        $companyNames = CompanyModel::getInstance()->column([], 'name');

        $planCost = ProductPlanCostModel::getInstance()->column([
            'product_id' => ['eq', $params['product_id']]
        ], 'work_cate');

        $workCateIds = $typeTxt = '';
        foreach (array_unique($planCost) as $k => $v)
        {
            $workCateIds .= empty($workCateIds) ? implode(',', json_decode($v, true)) : ','.implode(',', json_decode($v, true));

            $typeArr = WorkCategoryModel::getInstance()->column([
                'id' => ['in', json_decode($v, true)]
            ], 'title');
            $typeTxt .= (empty($typeArr) ? '' : (count($typeArr) > 1 ? intval(min($typeArr)) . '-' . intval(max($typeArr)) : intval(max($typeArr)))) . '类 ';
        }
        $isHigh = WorkTypeModel::getInstance()->value([
            'cate_id' => ['in', explode(',', $workCateIds)],
            'is_high' => ['eq', 1]
        ], 'is_high');

        $noInsuredArea = BackListService::getInstance()->getAreaBackListInfo([
            'productId' => $params['product_id']
        ]);
        $noinsureAreaIds = array_merge(array_keys($noInsuredArea['province']), array_keys($noInsuredArea['city']), array_keys($noInsuredArea['area']));
        $pid = Db::name('t_area')->where([
            'id' => ['in', $noinsureAreaIds]
        ])->column('pid', 'id');
        $pids = Db::name('t_area')->where([
            'id' => ['in', $pid]
        ])->column('pid', 'id');

        $noInsuredArea = MenuService::getInstance()->getMenuTree(Db::name('t_area')->where([
            'id' => ['in', array_unique(array_merge($noinsureAreaIds, $pid, $pids))]
        ])->select(), 0, 1);
        $noArea = '';
        foreach ($noInsuredArea as $k => $v)
        {
            $noArea .= empty($noArea) ? $v['name'] : '； '.$v['name'];
            if (!empty($v['child']))
            {
                $cs = '';
                foreach ($v['child'] as $kk => $vv)
                {
                    $noArea .= empty($cs) ? $vv['name'] : '、'.$vv['name'];
                    $cs = $vv['name'];
                    if (!empty($vv['child']))
                    {
                        $dh = '';
                        foreach ($vv['child'] as $kkk => $vvv)
                        {
                            $noArea .= empty($dh) ? $vvv['name'] : '、'.$vvv['name'];
                            $dh = $vvv['name'];
                        }
                    }
                }
            }
        }

        $proCommission = ProductChannelModel::getInstance()->column([
            'status' => ['eq', 1],
            'admin_id' => ['eq', $this->uid],
            'product_id' => ['eq', $params['product_id']]
        ], 'commission_type, promotion_commission, step_commission');
        $commission = 0;
        if (isset($proCommission[$params['product_id']]['commission_type']))
        {
            switch ($proCommission[$params['product_id']]['commission_type'])
            {
                case 1:
                    $commission = $proCommission[$params['product_id']]['promotion_commission'];
                    break;
                case 2:
                    $commission = min(array_column(json_decode($proCommission[$params['product_id']]['step_commission'], true), 'ratio'));
                    break;
            }
        }

        $agentId = AgentCompanyModel::getInstance()->value([
            'pro_id' => ['like', '%'.$params['product_id'].'%']
        ], 'agent_id');
        $agentName = AgentModel::getInstance()->value([
            'id' => ['eq', $agentId]
        ], 'title');

        $result = [
            'productId' => $params['product_id'],
            'productName' => $proInfo['product_name'],
            'companyName' => $companyNames[$proInfo['company']],
            'agent_id' => $agentId,
            'agent_name' => $agentName,
            'productHigh' => [
                $companyNames[$proInfo['company']].'承保',
            ],
            'proCommission' => $commission,
            'productDetailImg' => $proInfo['detail_img'],
            'insureAge' => $baseRule['insure_age']['startAge'].'-'.$baseRule['insure_age']['endAge'],
            'insureTime' => $proInfo['insureTime'],
            'insureNum' => min(array_column($baseRule['insure_num'], 'startNum')).'起投',
            'baseMoney' => $proInfo['base_money'],
            'nonInsured' => $proInfo['non_insured'],
            'insureWork' => $typeTxt . ($isHigh ? '含高空' : ''),
            'productCode' => $proInfo['product_code'],
            'noInsureArea' => empty($noArea) ? '无' : $noArea,
            'endTime' => '每天截止到'.$timeRule['insure_cut_off_time'].'之前，次日生效（T+1）；当天截单之后的订单延迟一天生效（T+2）；遇法定节假日顺延；',
            'desc' => $proInfo['product_desc'],
            'productKeywords' => $proInfo['product_keywords'],
            'productDesc' => $proInfo['desc'],
            'insuranceNotice' => $proInfo['insurance_notice'],
            'insureClause' => $insure_clause,
            'serviceAgreement' => $proInfo['service_agreement'],
            'commonProblem' => isset($proInfo['common_problem']) ? $proInfo['common_problem'] : '',
            'claimsGuide' => $proInfo['claims_guide'],
            'privacyDesc' => $proInfo['privacy_desc'],
            'importantNotices' => $proInfo['important_notices'],
            'occupationCate' => $proInfo['occupation_cate'],
            'insureFile' => $proInfo['insure_file'],
        ];
        //产品名称  产品亮点   承保年龄  保障期限  起保人数   基础保费  承保职业  拒保行业  拒保地区   产品编号   收单时间  产品详情   投保须知   保险条款   常见问题   理赔流程    隐私保护说明   特别提醒   职业类别表   投保资料

        return $result;
    }

    /**
     * 获取产品职业类别
     */
    public function getWorkType($params)
    {
        $Validate = new \think\Validate([
            'product_id' => 'require',
        ], [
            'product_id' => '产品标识无效'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }
        $planType = ProductPlatModel::getInstance()->value([
            'product_id' => ['eq', $params['product_id']]
        ], 'plan_type');
        if ($planType == 3)
        {
            $productWorkType = ProductPlanNoRateModel::getInstance()->column([
                'product_id' => ['eq', $params['product_id']]
            ], 'work_cate, plan_id');
            $workType = array_unique(array_column($productWorkType, 'work_cate'));
        }else{
            $productWorkType = ProductPlanCostModel::getInstance()->column([
                'product_id' => ['eq', $params['product_id']]
            ], 'work_cate, plan_id');
            $workType = array_unique(array_column($productWorkType, 'work_cate'));
        }
        $result = [];
        foreach ($workType as $k => $v)
        {
            $typeIds = json_decode($v, true);
            $typsArr = WorkCategoryModel::getInstance()->column([
                'id' => ['in', $typeIds]
            ], 'title');
            $work = WorkTypeModel::getInstance()->value([
                'cate_id' => ['in', $typeIds]
            ], 'id');
            if ($work)
            {
                $result[] = [
                    'ids' => $typeIds,
                    'value' => count($typsArr) > 1 ? intval(min($typsArr)) . '-' . max($typsArr) : max($typsArr)
                ];
            }
        }

        return $result;
    }

    /**
     * 根据职业类别获取工种
     */
    public function getWork($params)
    {
        $Validate = new \think\Validate([
            'workCateIds' => 'require',
        ], [
            'workCateIds' => '缺少职业类别标识'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }
        $cateList = WorkTypeModel::getInstance()->column([
            'cate_id' => ['in', $params['workCateIds']]
        ], 'title, pid, level');
        $cateList = MenuService::getInstance()->getMenuTree($cateList, 0, 1);
        foreach ($cateList as $k => $v)
        {
            if (empty($v['child'][0]['child'][0]['child']))
            {
                unset($cateList[$k]);
            }
            /*foreach ($v['child'][0]['child'] as $kk => $vv)
            {
                foreach ($vv['child'] as $kkk => $vvv)
                {
                    if (empty($vvv['child']))
                    {
                        unset($v['child'][0]['child'][$kk]['child'][$kkk]['child']);
                        $cateList[$k] = $v;
                    }
                }
            }*/
        }

        $result = $cateList;//CommonService::getInstance()->getTreeArr($cateList);
        return $result;
    }

    /**
     * 获取产品起保日期、保障期限
     */
    public function getProductTimeRule($params)
    {
        $Validate = new \think\Validate([
            'product_id' => 'require',
            'identification' => 'require',
        ], [
            'product_id' => '产品标识无效',
            'identification' => '时间标识无效'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }
        $productRule = ProductRuleModel::getInstance()->find($params['product_id']);
        $result = [
            'month' => [],
            'startTime' => $this->stampToDateTime(time() + 24 * 3600),
            'endTime' => $this->stampToDateTime(time() + 24 * 3600)
        ];
        if ($productRule)
        {
            $insureRule = json_decode($productRule['insure_rule'], true);
            $timeRule = json_decode($productRule['time_rule'], true);
            $timeRule['identification'] = $params['identification'];
            $insureTime = self::getEffectiveDate($timeRule);
            sort($insureRule['month']);
            $result = [
                'month' => $insureRule['month'],
                'startTime' => $insureTime[0],
                'endTime' => $insureTime[1],
            ];
        }
        $companyId = ProductModel::getInstance()->productValue([
            'id' => ['eq', $params['product_id']]
        ], 'company');
        $companyInfo = CompanyModel::getInstance()->find($companyId);
        $result['premiumSetting'] = $companyInfo['premium_setting'];
        $result['premiumRule'] = $companyInfo['premium_rule'];
        $result['isSpecial'] = $companyInfo['is_special'];
        $result['specialTicket'] = $companyInfo['special_ticket'];
        return $result;
    }

    /**
     * 判断生效日期
     */
    public function getEffectiveDate($timeRule)
    {
        //判断后续10天的第一个工作日
        $days = [1,2,3,4,5,6,7,8,9,10];
        $addDay = 0;

        //截单时间
        switch ($timeRule['identification'])
        {
            case 1:
                $cutOffTime = datetime(strtotime($timeRule['insure_temporary_cut_off_time']), 'Y-m-d') != datetime(time(), 'Y-m-d') ? datetime(time(), 'Y-m-d').' '.$timeRule['insure_cut_off_time'] : $timeRule['insure_temporary_cut_off_time'];
                $startDate = $timeRule['start_time_date'];
                $advanceDay = $timeRule['insure_advance_days'];
                $isWeek = $timeRule['insure_week_is_work'];
                break;
            case 2:
                $cutOffTime = datetime(strtotime($timeRule['correction_temporary_cut_off_time']), 'Y-m-d') != datetime(time(), 'Y-m-d') ? datetime(time(), 'Y-m-d').' '.$timeRule['correction_cut_off_time'] : $timeRule['correction_temporary_cut_off_time'];
                $startDate = $timeRule['correction_start_time_date'];
                $advanceDay = $timeRule['correction_advance_days'];
                $isWeek = $timeRule['correction_week_is_work'];
                break;
        }

        foreach ($days as $item)
        {
            //工作日为0，休息日1，节假日2， 取不到结果 返回-1
            $isWorkDay = CommonService::getInstance()->isHoliday($this->stampToDate(time() + $item * 24 * 3600));
            $isWorkDay = $isWorkDay == 1 && empty($isWeek) ? 0 : $isWorkDay;
            if (empty($isWorkDay))
            {
                $addDay = $addDay + $item;
                break;
            }
        }
        $addDay = empty($isWeek) ? 0 : $addDay;
        $addDay = datetime(time() + 60 * 1, 'Y-m-d H:i') >= $cutOffTime ? $addDay + (empty($isWeek) ? 2 : 1) : $addDay;
        $addDay = $startDate >= $addDay ? $startDate : $addDay;

        $startTime = datetime(time() + $addDay * 24 * 3600, 'Y-m-d');
        $endTime = datetime(strtotime($startTime) + intval($advanceDay) * 24 * 3600, 'Y-m-d');
        return [
            $startTime, $endTime
        ];
    }

    /**
     * 获取方案信息
     */
    public function getProductPlan($params)
    {
        $Validate = new \think\Validate([
            'product_id' => 'require',
        ], [
            'product_id' => '产品标识无效'
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }
        $planList = ProductPlatModel::getInstance()->select([
            'product_id' => ['eq', $params['product_id']]
        ]);
        $result = [];
        $isAllDays = 0;
        $disabilityRatio = [];
        foreach ($planList as $k => $v)
        {
            foreach ($v as $kk => $vv)
            {
                //!empty($vv) &&
                if (!empty($v['death_quota']) && !empty($v['medical_quota']))
                {
                    switch ($kk)
                    {
                        case 'disability_ratio':
                            $disaRatio = json_decode($vv, true);
                            $disabilityRatio = $disaRatio;
                            break;
                        case 'is_expand_24_hours':
                            $isAllDays = $vv;
                            break;
                        default:
                            $result[$k][$kk] = $vv;
                            break;
                    }
                }
            }
        }
        //获取承保年龄范围、起保人数
        $productRule = ProductRuleModel::getInstance()->find($params['product_id']);
        $baseRule = json_decode($productRule['base_rule'], true);
        $insureNum = [];
        foreach ($baseRule['insure_num'] as $k => $v)
        {
            $insureNum[] = $v['startNum'];
        }

        return [
            'isAllDays' => $isAllDays,
            'disaRatio' => $disabilityRatio,
            'insureNum' => min($insureNum),
            'insureAge' => $baseRule['insure_age'],
            'plan' => $result
        ];
    }

    /**
     * 根据产品方案 投保人数 伤残比例  是否扩展24小时 保障期限 职业工种类别 获取保费
     */
    public function getProductPlanMoney($params)
    {
        $Validate = new \think\Validate([
            'product_id' => 'require',
            'planId' => 'require',
//            'disabRatio' => 'require',
            'isAllDays' => 'require',
            'guaranteePeriod' => 'require',
            'workType' => 'require',
            'workId' => 'require',
        ], [
            'product_id' => '产品标识无效',
            'planId' => '方案标识无效',
//            'disabRatio' => '伤残比例无效',
            'isAllDays' => '是否扩展24小时必传',
            'guaranteePeriod' => '保障期限无效',
            'workType' => '工种类别必传',
            'workId' => '工种必传',
        ]);
        if (!$Validate->check($params))
        {
            $this->error($Validate->getError());
        }

        $productRule = ProductRuleModel::getInstance()->find($params['product_id']);
        $baseRule = json_decode($productRule['base_rule'], true);
        $insureNum = $baseRule['insure_num'][0]['startNum'];

        $insureNum = isset($params['insureNum']) ? $params['insureNum'] : $insureNum;
        //根据产品方案 投保人数 伤残比例  是否扩展24小时 保障期限 职业工种类别 获取保费

        //现获取基础保费  获取伤残比例 扩展24小时比例 投保人数比例 保障期限比例
        $platInfo = self::getProductPlan([
            'product_id' => $params['product_id']
        ]);

        $disabRatio = $allDayRatio = $personRatio = $workRatio = 1;
        $guaranteeRatio = 0;

        $disabRatio = $params['disabRatio'] == 'is_five_percent' ? $platInfo['disaRatio']['five_ratio'] : ($params['disabRatio'] == 'is_one_percent' ? $platInfo['disaRatio']['one_ratio'] : (isset($platInfo['disaRatio']['ten_ratio']) ? $platInfo['disaRatio']['ten_ratio'] : 1));

        foreach ($baseRule['work_type'] as $k => $v)
        {
            if (in_array($params['workId'], $v['work_cate']))
            {
                $workRatio = $v['insure_ratio'];break;
            }
        }
        foreach ($baseRule['insure_num'] as $k => $v)
        {
            if ($insureNum >= $v['startNum'] && $insureNum <= $v['endNum'])
            {
                $personRatio = $v['insureRate'];break;
            }
        }
        $allDayRatio = !empty($params['isAllDays']) ? $platInfo['plan'][0]['insure_ratio_24_hours'] : $allDayRatio;
        $insureRule = json_decode($productRule['insure_rule'], true);
        $monthRatioKey = array_search($params['guaranteePeriod'], $insureRule['month']);

        $guaranteeRatio = isset($insureRule['month_rate'][$monthRatioKey]) ? $insureRule['month_rate'][$monthRatioKey] : $params['guaranteePeriod'] * 10;
        if ($baseRule['is_work_type'])
        {
            foreach ($insureRule as $k => $v)
            {
                if (strpos($k, 'month_rate') !== false)
                {
                    $mRatio = explode('_', $k);
                    $intWorkType = WorkTypeModel::getInstance()->value([
                        'id' => ['eq', $params['workId'][3]]
                    ], 'grade');
                    if (in_array($intWorkType, $mRatio))
                    {
                        $guaranteeRatio = isset($insureRule[$k][$monthRatioKey]) ? $insureRule[$k][$monthRatioKey] : $params['guaranteePeriod'] * 10;
                        break;
                    }
                }
            }
        }

        //获取基础保费
        switch ($platInfo['plan'][0]['plan_type'])
        {
            case 1:
                $baseMoney = ProductPlanCostModel::getInstance()->value([
                    'product_id' => ['eq', $params['product_id']],
                    'plan_id' => ['eq', $params['planId']],
                    'work_cate' => ['eq', json_encode($params['workType'])]
                ]);
                break;
            case 2:
                $extendMoney = ProductPlanCostModel::getInstance()->value([
                    'product_id' => ['eq', $params['product_id']],
                    'plan_id' => ['eq', $params['planId']],
                    'work_cate' => ['eq', json_encode($params['workType'])]
                ], 'extend_money');
                $extendMoney = json_decode($extendMoney, true);
                $key = [
                    'is_one_percent' => 'one_money',
                    'is_five_percent' => 'five_money',
                    'is_ten_percent' => 'ten_money'
                ];
                $baseMoney = $extendMoney[$key[$params['disabRatio']]];
                break;
            case 3:
                $baseMoney = ProductPlanNoRateModel::getInstance()->value([
                    'product_id' => ['eq', $params['product_id']],
                    'plan_id' => ['eq', $params['planId']],
                    'month' => ['eq', $params['guaranteePeriod']]
                ]);
                $guaranteeRatio = 100;//无费率方案 不根据投保月份费率计算价格
                break;
            default:
                $baseMoney = ProductPlanCostModel::getInstance()->value([
                    'product_id' => ['eq', $params['product_id']],
                    'plan_id' => ['eq', $params['planId']],
                    'work_cate' => ['eq', json_encode($params['workType'])]
                ]);
                break;
        }

        $policyMoney = $baseMoney * $disabRatio * $allDayRatio * $personRatio * $guaranteeRatio / 100;
        return [
            'policyMoney' => $policyMoney + 0.00000001
        ];
    }
}